package com.hmily.dubbo.provider.spi.ioc.impl;

import com.hmily.dubbo.provider.spi.ioc.AnimalService;
import com.hmily.dubbo.provider.spi.ioc.HumanService;
import org.apache.dubbo.common.URL;

import java.util.HashMap;
import java.util.Map;

/**
 * <h1>Yuki 包装类。</h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2021-11-14
 */
public class YukiServiceWrapper implements HumanService {

    private HumanService humanService;
    private AnimalService catService;
    private AnimalService rabbitService;
    private AnimalService cat;

    public YukiServiceWrapper(HumanService humanService) {
        this.humanService = humanService;
    }

    public void setCat(AnimalService catService){
        this.cat = catService;
    }

    public void setCatService(AnimalService catService){
        this.catService = catService;
    }

    public void setRabbitService(AnimalService rabbitService){
        this.rabbitService = rabbitService;
    }

    @Override
    public String getName(URL url) {
        String preMsg = "[YukiServiceWrapper--pre]\r\n";

        Map catMap = new HashMap();
        catMap.put("animal", "cat");
        catMap.put("name", "cat");
        URL catUrl = new URL(null, null, 0, catMap);
        String catMsg = catService.getWeight(catUrl);
        catMsg = catMsg + "\r\n";


        Map rabbitMap = new HashMap();
        rabbitMap.put("animal", "rabbit");
        rabbitMap.put("name", "rabbit");
        URL rabbitUrl = new URL(null, null, 0, rabbitMap);
        String rabbitMsg = rabbitService.getWeight(rabbitUrl);
        rabbitMsg = rabbitMsg + "\r\n";

        String result = humanService.getName(url);

        String postMsg = "\r\n[YukiServiceWrapper--post]\r\n";

        return preMsg + catMsg + rabbitMsg + result + postMsg;
    }
}
